/**************************
* @Summary
* @Author 20009200303 赵传博
* @Date 6/15/2022
* @Note
*****************************/

#include "Clock.h"

Clock::Clock(int _hour, int _minute, int _second) {
    hour = _hour;
    minute = _minute;
    second = _second;
}

void Clock::get(int & h, int & m, int * s) {
    h = hour;
    m = minute;
    *s = second;
}

bool Clock::adjust(int h, int m, int s) {
    if(!isValid(h, m, s)) return false;
    hour = h;
    minute = m;
    second = s;
    return true;
}

bool Clock::isValid(int h, int m, int s) {
    return !(h < 0 || h > 23 || m < 0 || m > 59 || s < 0 || s > 59);
}

void Clock::update() {
    if(second != 59) second++;
    else{
        if(minute != 59){
            minute++;
            second = 0;
        }else{
            if(hour != 23){
                hour++;
                minute = 0;
                second = 0;
            }else{
                hour = 0;
                minute = 0;
                second = 0;
            }
        }
    }
}

ostream &operator<<(ostream &os, Clock &c) {
    std::cout << c.hour << ":" << c.minute << ":" << c.second;
    return os;
}
